import 'package:flu_framework/common/utility/native_channel_util.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:url_launcher/url_launcher.dart';

class UrlLauncherUtil{
  /// 启动拨号页
  static Future<void> launchTelURL(String phone) async {
// 拨打电话以<phone number>使用默认电话应用程序
    final Uri uri = Uri.parse('tel:$phone');
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      Fluttertoast.showToast(msg: "拨号失败！");
    }
  }


  /// 打开链接
  static Future<void> launchWebURL(String url) async {
    final Uri uri = Uri.parse(url);
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      Fluttertoast.showToast(msg: "打开链接失败！");
    }
  }
  /// 发送短信
  static Future<void> launchSmsURL(String phone) async {
    final Uri uri = Uri.parse('sms: $phone');
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      Fluttertoast.showToast(msg: "发送短信失败！");
    }
  }
  /// 发送邮件
  static Future<void> launchEmailURL(String email, String subject, String body) async {
    final Uri uri = Uri.parse('mailto:$email?subject=$subject&body=$body');
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      NativeChannelUtil.openEmail(email);
    }
  }


}



